package com.bi.design.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bi.design.entity.DeviceData;
import com.bi.design.mapper.DeviceDataMapper;
import com.bi.design.pojo.BasePage;
import com.bi.design.query.DeviceDataPageQuery;
import com.bi.design.service.DeviceDataService;
import com.bi.design.tools.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Objects;

@Service
@RequiredArgsConstructor
public class DeviceDataServiceImpl extends ServiceImpl<DeviceDataMapper, DeviceData> implements DeviceDataService {
    private final DeviceDataMapper deviceDataMapper;


    @Override
    public Long addAndEdit(DeviceData dto) {
        if (Objects.isNull(dto.getId())) {
            deviceDataMapper.insert(dto);
        } else {
            deviceDataMapper.updateById(dto);
        }
        return dto.getId();
    }

    @Override
    public PageInfo<DeviceData> getPageByDeviceTypeQuery(String deviceType, DeviceDataPageQuery query) {
        return deviceDataMapper.selectPageByDeviceTypeQuery(new PageInfo<>(query.getPageCurr(), query.getPageSize()),deviceType,query);
    }

}
